package fi.jamk.ourcookingapp.backend;

import java.util.List;

/**
 * This is for some supporting functions
 * @author Marius
 */
public class MyTools {

	/**
	 * Checks whether the input is null or empty string
	 * @param input
	 * @return
	 */
	public static boolean isEmpty(String input) {
		if(input == null){
			throw new NullPointerException();
		}
		if(input.equals("")){
			return true;
		}
		return false;
	}

	/**
	 * Building a string with every string in the list separating each by sep
	 * @param sep
	 * @param list
	 * @return
	 */
	public static String implode(String sep, List<String> list) {
		if(list.isEmpty()){
			return "";
		}
		StringBuilder builder = new StringBuilder();
		builder.append(list.remove(0));
		for (String str : list) {
			builder.append(sep + " ");
			builder.append(str);
		}
		return builder.toString();
	}

}
